package com.kefu.web.im.netty.client;

import java.util.List;

import com.corundumstudio.socketio.SocketIOClient;
import com.google.common.collect.ArrayListMultimap;

public class IMClientPool implements NettyIOClientPool {

	private ArrayListMultimap<String, SocketIOClient> imClientsMap = ArrayListMultimap.create();

	public List<SocketIOClient> getClients(String key) {
		return imClientsMap.get(key);
	}

	public void putClient(String key, SocketIOClient client) {
		imClientsMap.put(key, client);
	}

	public void removeClient(String key, String id) {
		List<SocketIOClient> keyClients = this.getClients(key);
		for (SocketIOClient client : keyClients) {
			if (client.getSessionId().toString().equals(id)) {
				keyClients.remove(client);
				break;
			}
		}
		if (keyClients.size() == 0) {
			imClientsMap.removeAll(key);
		}
	}
}
